﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using T_Material.API.Application.Commands.PurchaseCommand;
using T_Material.API.Application.Commands.StatisticsCommand;
using T_Material.API.Application.Commands.WarehousingCommand;

namespace T_Material.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = nameof(ApiversionInfo.入库管理))]

    public class WarehousingAPIController : ControllerBase
    {
        private readonly IMediator mediator;
        public WarehousingAPIController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加物资入库
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> WarehousingAdd(WarehousingCreatedCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 删除物资入库
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> WarehousingDelete([FromQuery] WarehousingDeleteCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 修改物资入库
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> WarehousingUpdate(WarehousingUpdateCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 批删物资入库
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> WarehousingDels([FromQuery] WarehousingDelsCommand command)
        {
            try
            {
                return await mediator.Send(command);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
